home *** CD-ROM | disk | FTP | other *** search
- Path: islay.ssl.berkeley.edu!korpela
- From: korpela@islay.ssl.berkeley.edu (Eric J. Korpela)
- Newsgroups: comp.sys.cbm,gnu.gcc.help,comp.sys.atari.8bit
- Subject: Re: GNU C-compiler port to 6502
- Date: 30 Mar 1996 01:14:22 GMT
- Organization: Cal Berkeley-- Space Sciences Lab
- Message-ID: <4ji1te$dnk@agate.berkeley.edu>
- References: <4irqpb$7pc@esel.cosy.sbg.ac.at> <4jbmcf$733@news.iastate.edu> <4jgc70$lmt@dodo.cosy.sbg.ac.at>
- NNTP-Posting-Host: islay.ssl.berkeley.edu
-
- In article <4jgc70$lmt@dodo.cosy.sbg.ac.at>,
- Gerhard Wesp <gwesp@dodo.cosy.sbg.ac.at> wrote:
- >
- >> But the biggest choice of all is whether to let GCC manage the 6502
- >>registers directly, or to use a sort of ``virtual machine'' model on
- >>the 6502 that looks better to GCC (page zero registers, manipulated by
- >>simple bits of native code that GCC thinks are single instructions).
- >
- > Exactly such sort of thing I thought of. The code could be
- >implemented as macros and as subroutines for the more complex things
- >like multiplicatio, division, floating point ops etc. (or we use
- >pseudo ops triggered by a brk...)
-
- The biggest problem with this is interfacing to the optimizer. Suppose
- we design macros that do the instructions for our 32 bit machine with
- 8 32bit (zero page starting at $80) pseudoregisters. Let's run through
- a two instruction example.
-
- register int r0 = (unsigned short)mem1 & (int)mem2;
-
- In our macro language, gcc might compile that as
-
- ldsz _mem1,%r0
- andl %r0,_mem2,%r0
-
- Our macros are
-
- ldsz _mem1,%r0 defined as
- LDX #1
- LDY #0
- 0: LDA _mem1,X
- STA $80,X
- STY $82,X
- DEX
- BPL 0b
-
- andl %r0,_mem2,%r0 defined as
- LDX #3
- 0: LDA _mem2,X
- AND $80,X
- STA $80,X
- DEX
- BPL 0b
-
- Since gcc wouldn't know anything about the internal structure of the macros,
- it would just concatanate the two instruction macros. Whereas a native 65C02
- C compiler outputting real 65C02 instructions could notice that the LDX #3
- could be changed to a LDX #1 and optimize the instruction sequence. An even
- better optimization would be to combine the two into one loop like this:
-
- LDX #1
- LDY #0
- 0: LDA _mem1,X
- AND _mem2,X
- STA $80,X
- STY $82,X
- DEX
- BPL 0b
-
- That's a reduction from 32 to 14 cycles (incorrectly assuming 1/instruction)
- in execution time and a reduction in size from 26 to 17 bytes in size. On
- a 6502 both of those are important things. (64K address space, 1-2 Mhz)
-
- A native 6502 compiler could do that kind of optimization, our "macro"
- compiler couldn't without an additional optimizer. My guess is that the
- optimizer would be as hard to write as a native 6502 C compiler.
-
- IMHO, the answer is "Yes, it would be possible to alter gcc to output a
- pseudocode that could be compiled to 6502 instructions, but it would be
- hard to optimize the resulting code."
-
- Eric
- --
- Eric Korpela | An object at rest can never be
- korpela@ssl.berkeley.edu | stopped.
- <a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
- Click here for more info.</a>
-